Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

discards packets which are not (fully) populated #3508

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

behzadnouri
Copy link

Problem

Not discarding packets which are not (fully) populated is bug prone or might waste resources.

Summary of Changes

Discard packets which are not (fully) populated.

Not discarding packets which are not (fully) populated is bug prone or
might waste resources.
@behzadnouri behzadnouri requested a review from steviez November 6, 2024 22:07
@@ -90,9 +90,11 @@ impl PacketBatch {
// break the payload into smaller messages, and here any errors
// should be propagated.
error!("Couldn't write to packet {:?}. Data skipped.", e);
packet.meta_mut().set_discard(true);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea makes sense, what do you think about moving line inside Packet::populate_packet so that we get this behavior across the board, not just from this one PacketBatch constructor ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather not do that.
If there is a failure, Packet::populate_packet is returning the error to the caller. The caller may choose to either:

  1. discard the packet (like in this commit).
  2. or, reuse the packet and write the next payload to it. In which case it shouldn't be marked discard.

The problem with the current code is that the caller is effectively ignoring the error.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or, reuse the packet and write the next payload to it. In which case it shouldn't be marked discard.

Sure, but if the caller is making a conscious decision to "recycle" the packet, it doesn't seem unreasonable to call .set_discard(false) to clean up this "dirtied" packet

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would require the caller to know the implementation details Packet::populate_packet and what side effects it causes when it fails, which is generally not good.

The error returned by Packet::populate_packet however is part of the signature and explicit.

@behzadnouri behzadnouri requested a review from steviez November 7, 2024 01:02
Copy link

@steviez steviez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this as-is; I'm probably lacking some context for the situation you have in mind.

On a related note, I'm currently working on a change to clean this up:

agave/sdk/packet/src/lib.rs

Lines 210 to 213 in 966c3c8

#[allow(clippy::uninit_assumed_init)]
impl Default for Packet {
fn default() -> Self {
let buffer = std::mem::MaybeUninit::<[u8; PACKET_DATA_SIZE]>::uninit();

As part of that work, I'll likely be reviewing the various places packets are created & populated, so we can revisit incase I develop a stronger opinion on this

@@ -90,9 +90,11 @@ impl PacketBatch {
// break the payload into smaller messages, and here any errors
// should be propagated.
error!("Couldn't write to packet {:?}. Data skipped.", e);
packet.meta_mut().set_discard(true);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or, reuse the packet and write the next payload to it. In which case it shouldn't be marked discard.

Sure, but if the caller is making a conscious decision to "recycle" the packet, it doesn't seem unreasonable to call .set_discard(false) to clean up this "dirtied" packet

@behzadnouri behzadnouri merged commit 91edf66 into anza-xyz:master Nov 7, 2024
29 checks passed
@behzadnouri behzadnouri deleted the discard-bad-packets branch November 7, 2024 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants